<div class="table-frame padding">
    <?php include('template.advanced-search.php'); ?>
    <div id="subscription-buttons" class="group padding margin-bottom">
        <a class="show-tool-tip grey newsub icon-button left" title="Create a brand new subscription, or select from users who are currently unsubscribed." href="<?php echo $Controller->page_url('edit'); ?>">NEW SUBSCRIPTION</a>
        <a class="show-tool-tip grey export icon-button left" title="Generate a full report of your active, paused and expiring subscriptions." href="<?php echo $Controller->page_url('reports');?>">SUBSCRIPTION REPORT</a>    
    </div>
    
    
    <table id="subscription-list" class="subscription-table">
    <thead>
        
        <tr class="paged-nav">
            <td colspan="11">
            <small>
            <?php  
            printf("Page %s of %s - showing %s-%s of %s subscriptions", 
            ($paged+1), 
            $total_pages, 
            ($session->setting_records_per_page * ($paged + 1))-$session->setting_records_per_page + 1, 
            (($paged+1)==$total_pages) ? $total_subscriptions : ($session->setting_records_per_page * ($paged + 1)), 
            $total_subscriptions
            );
            ?> 
            </small>
            </td>
        </tr>
        <?php 
            if( $is_search ) {
            ?>
            <tr>
                <td colspan="11">
                    <strong>Results for:</strong>
                    <ul class="search-display">
                    <?php 
                    foreach($_GET as $k => $v ) {
                        if ( $k != 'page' && $k != 'action' && !empty( $v ) ) 
                            echo  "<li><strong>$k</strong> as <strong>$v</strong></li>";
                    }
                    ?>
                    </ul>
                </td>
            </tr>
            <?php    
            }
            ?>
        <tr class="heading-row skin-gradient">
        <td>#</td>
        <th>ID</th>
        <th>
        <?php 

        if($unique_names && count($subscription_set) >= 1) :
        ?>
        
            <form method="post" action="edit.php">
                <label for="user-autosort">Find on page: </label>
                <input name="user_name" id="user-autosort" type="text" placeholder="User Name"/>
            </form>
        
        <?php else: echo "User"; endif; ?>
        </th>
        
        <th>Status</th>
        <th>Street Address</th>
        <th>
            City
            <a href="<?php echo $Controller->page_url();?>&action=sort&sort_by=city&order=asc" class="show-tool-tip" title="Order by City">&nabla;</a>
            <a href="<?php echo $Controller->page_url();?>&action=sort&sort_by=city&order=desc" class="show-tool-tip" title="Order by City">&Delta;</a>
        </th>
        <th>
            Region 
            <a href="<?php echo $Controller->page_url();?>&action=sort&sort_by=province&order=asc" class="show-tool-tip" title="Order by Province">&nabla;</a>
            <a href="<?php echo $Controller->page_url();?>&action=sort&sort_by=province&order=desc" class="show-tool-tip" title="Order by Province">&Delta;</a>
        </th>
        <th>Remaining</th>
        <th>Progress</th>
        <th>Expires On</th>
        <th>Controls</th>
        </tr>       
    </thead>
    
    <tbody>
        <?php
        if ( isset($subscription_set) && is_array( $subscription_set ) && count($subscription_set) > 0 ) :
        $i = 0;
        foreach ( $subscription_set as $sub ) : if ($sub) :
        $i ++;
            
        ?>
        <tr <?php echo ($sub->is_expiring()) ? 'class="expiring"' : ''; ?>>
            <td><?php echo $i + $offset; ?></td>
            <td><?php echo $sub->attr('subscription_id'); ?></td>
            <td class="table-displayname" data-displayname="<?php echo $sub->user->get_attr('displayname'); ?>"><?php $sub->user->edit_link(); ?></td>
            <td><?php echo $sub->get_status(); ?></td>
            
            <td><?php echo $sub->user->get_simple_location(); ?></td>
            <td><?php echo $sub->user->attr('city'); ?></td>
            <td><?php echo $sub->user->attr('province'); ?></td>
            
            <td>
                <strong>
                    <?php
                        if ( !isset($filter) || $filter != 'expired' ) {
                            $sub->current_week(); echo " of " . $sub->subscription_length; 
                        } else {
                            echo "Expired";
                        }
                    
                    ?>
                </strong>
            </td>
            <td>
                <?php
                    if ( !isset($filter) || $filter != 'expired' ) {
                        echo '<div class="percent-bar"><span data-percent="'.$sub->get_percent().'"></span></div>';
                    } else {
                        echo "Expired";
                    }
                
                ?>
            </td>
            <td><?php echo date("M j Y", strtotime($sub->get_end_date())); ?></td>
            <td class="controls group">
                <a class="show-tool-tip" href="<?php echo $sub->user->get_edit_link();?>" title="Edit <?php echo $sub->user->displayname(); ?>"><img src="css/ui/edit-16.png" /></a>
                <?php $sub->user->email_link(); ?>
                <a class="show-tool-tip" href="<?php echo $Controller->page_url(); ?>&delete=user&id=<?php $sub->user->attr('user_id'); ?>" title="Deleting a user is <em>PERMANENT</em> and highly discouraged."> Delete </a>
            </td>
        </tr>
        <?php
        endif; endforeach;
        else:
            echo '<tr><td colspan="11"><strong>Nothing found</strong></td><tr>';
        endif;
        ?>
    </tbody>

    
    <tfoot>
        <?php if (count($subscription_set) >= 12 ) : ?>
        <tr  class="heading-row skin-gradient">
            <th>#</th>    
            <th>ID</th>
            <th>User</th>
            <th>Status</th>
            <th>Street Address</th>
            <th>City</th>
            <th>Region</th>
            <th>Remaining</th>
            <th>&nbsp;</th>
            <th>Expires On</th>
            <th>Controls</th>
        </tr>
        <?php endif; ?>
        <?php if ($total_pages > 1 ) : ?>
        <tr class="paged-nav">
            <td colspan="11">
                <p>
                <?php  echo "Page " . ($paged+1); ?>
                </p>
                <span class="page-links">
                <?php
               
                for ( $count = 0; $count < $total_pages; $count ++ ) {
                    
                    $class = "paged-link left ". (($count == $paged) ? 'skin-gradient active' : 'default');
                    $paged_url = ( $count > 0 ) ? '&paged='.$count : '';
                    echo '<a class="'.$class.'"';
                    echo 'href="'.$Controller->get_raw_get_url().$paged_url.'"';
                    echo '>'.($count + 1).'</a>';
                }
                 ?>
               </span>
            </td>
        </tr>
       <?php endif; ?>
    </tfoot>
    
    
    </table>
</div>